using NUnit.Framework;
using Rhino.Mocks;

namespace Rubikev.Test.Common
{
   /// <summary>
   /// Base class for tests using mocks
   /// </summary>
   public abstract class MockTestBase
   {
      /// <summary>
      /// The MockRepository containing all mocks for the test. Is recreated prior to every test
      /// </summary>
      protected MockRepository Mocks { get; private set; }

      /// <summary>
      /// Sets up <see cref="Mocks"/>, calls <see cref="SetUpMocks"/>, replays all, then calls <see cref="PostReplayAllMocks"/>
      /// </summary>
      [SetUp]
      public virtual void SetUp()
      {
         Mocks = new MockRepository();
         SetUpMocks();
         Mocks.ReplayAll();
         PostReplayAllMocks();
      }

      /// <summary>
      /// Override this to setup any mocks before each test
      /// </summary>
      protected virtual void SetUpMocks()
      {
      }

      /// <summary>
      /// Override this to carry out any operations after ReplayAll is called on <see cref="Mocks"/> before each test
      /// </summary>
      protected virtual void PostReplayAllMocks()
      {
      }

      /// <summary>
      /// Verifies all mock expectations have been carried out after each test
      /// </summary>
      [TearDown]
      public virtual void TearDown()
      {
         PreVerifyMocks();
         Mocks.VerifyAll();
         PostVerifyMocks();
      }

      /// <summary>
      /// Override this to carry out any operations before VerifyAll is called on <see cref="Mocks"/> after each test
      /// </summary>
      protected virtual void PreVerifyMocks()
      {
      }

      /// <summary>
      /// Override this to carry out any operations after VerifyAll is called on <see cref="Mocks"/> after each test
      /// </summary>
      protected virtual void PostVerifyMocks()
      {
      }
   }
}